<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>统一管理平台管理员登录</title>

  <link href="__PUBLIC__/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="__PUBLIC__/dist/css/signin.css" rel="stylesheet">

    <style type="text/css"> .error{width: 100%;color: darkred} </style>
</head>

<body>

<div class="signin">
  <div class="signin-head"><img src="__PUBLIC__/dist/img/avatar04.png" alt="" class="img-circle"></div>
  <form class="form-signin" method="post" id="mform" name="mform" >
    <input type="text" name="username" id="username" class="form-control" placeholder="用户名"   autofocus />
    <input type="password" name="pwd" id="pwd" class="form-control" placeholder="密码"   />


    <button class="btn btn-lg btn-warning btn-block" type="submit">登录</button>
      <BR>
      <div class="alert alert-danger" style="display: none"></div>

  </form>
</div>

<include file="./Application/Home/View/Tpl/commjs.html" />
<script src="__PUBLIC__/dist/js/jquery.validate.js"></script>

<script type="text/javascript">
    $(function() {

        $('input[name="username"]').focus();

        $("#mform").validate({
            rules:{
                username:{
                    required:true,
                    maxlength:20,
                    minlength:4
                },
                pwd:{
                    required:true,
                    maxlength:20,
                    minlength:4
                }
            },
            messages: {
                username: {
                    required:'请输入用户名',
                    minlength: jQuery.format("用户名不能小于{0}个字符")
                },
                pwd: {
                    required:'请输入密码',
                    minlength: jQuery.format("密码不能小于{0}个字符")
                }
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent());
                $(".alert-danger").show();
                $(".alert-danger").html(error);
            },

            submitHandler: function(form) {  //通过之后回调

                var param = $("#mform").serialize();
                $.ajax({
                    url : "{:U('/Home/Login/login','',false)}",
                    type : "post",
                    dataType : "html",
                    cache:false,
                    data: param,
                    success:function(msg){
                        //alert(msg);
                        var result=eval('(' + msg + ')');
                        if(!result.status){
                            $(".alert-danger").show();
                            $(".alert-danger").html(result.info);
                            setTimeout(function(){$(".alert-danger").hide()}, 3000 );

                        }
                        else
                        {
                            window.location.href=result.url;
                        }
                    }
                });
            },
            invalidHandler: function(form, validator) {  //不通过回调
                return false;
            }
        });


    });
</script>
</body>


</html>
